//
//  OrderTeacherButton.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/4/10.
//  Copyright (c) 2017 蓝布鲁. All rights reserved.
//

#import "OrderTeacherButton.h"

@interface OrderTeacherButton()


@end

@implementation OrderTeacherButton

- (instancetype)initWithFrame:(CGRect)frame {
    if(self=[super initWithFrame:frame]) {
        // 设置圆角边框
        self.backgroundColor = [UIColor clearColor];
        self.layer.masksToBounds = true;
        self.layer.cornerRadius = 7;
        self.layer.borderColor = [UIColor orangeColor].CGColor;
        self.layer.borderWidth = 1.5;

        self.userInteractionEnabled = false;
        // 手动改变button disable 效果
        self.adjustsImageWhenDisabled = false;

        // 设置文字
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];

    }
    return self;
}



- (void)setType:(OrderTeacherButtonType)type {
    _type = type;
    switch (type){
        case CancelTeacherEnable:
            [self setTitle:@"取消预约" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case CancelTeacherDisable:
            [self setTitle:@"导师已确认" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case OrderTeacherEnable:
            [self setTitle:@"预约导师" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case EvalutionTeacherEnable:
            [self setTitle:@"评价导师" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case CheckEvaluateEnable:
            [self setTitle:@"查看评价" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case BeCanceledEnable:
            [self setTitle:@"导师已取消" forState:UIControlStateNormal];
            self.enabled = true;
            break;
    }
}

- (void)setCode:(NSInteger)code {
    _code = code;
    self.type = [self buttonTypeWithCode:code];
}

-(OrderTeacherButtonType)buttonTypeWithCode:(NSInteger)code {
    switch (code){
        case 1:     // 已预约,已评价(查看评价)
            return CheckEvaluateEnable;
        case 2:     // 已预约,没评价(评价导师)
            return  EvalutionTeacherEnable;
        case 3:     // 可预约
            return OrderTeacherEnable;
        case 4:     // 已预约,没开始(取消预约)
            return CancelTeacherEnable;
        case 5:     // 不可取消
            return CancelTeacherDisable;
        case 6:
            return BeCanceledEnable;
    }
    return 0;
}



- (void)setEnabled:(BOOL)enabled {
    [super setEnabled:enabled];
    if(enabled == false){
        self.layer.borderColor = [UIColor grayColor].CGColor;
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    } else {

        self.layer.borderColor = [UIColor orangeColor].CGColor;
        [self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

- (void)sizeToFit {
    [super sizeToFit];
    self.width = self.width + 15;
}

@end
